﻿<%@ WebHandler Language="C#" Class="AdminHandler" %>

using System;
using System.Web;
using BusinessObjects.BO_GetObjects;
using System.Data;
using System.Text;

public class AdminHandler : IHttpHandler
{
    private string action, result = string.Empty;
    public void ProcessRequest(HttpContext context)
    {
        action = context.Request["action"].ToString();        
        switch (action)
        {
            case "tags":
                result = Tags(context.Request.QueryString["q"].ToString());
                break;
            case "related":
                result = Related(context.Request.QueryString["q"].ToString());
                break;
            default:
                break;
        }
        context.Response.Write(result);
    }

    private string Related(string prefixText)
    {
        if (prefixText == null)
            prefixText = "a";
        StringBuilder sb = new StringBuilder();
        DataTable objDT = BO_portal_articles.Search(prefixText, 10);
        foreach (DataRow drow in objDT.Rows)
        {
            sb.Append(drow["FULL_ARTICLE_TITLE"]).Append(Environment.NewLine);
        }
        return sb.ToString();
    }

    private string Tags(string prefixText)
    {
        if (prefixText == null)
            prefixText = "a";
        StringBuilder sb = new StringBuilder();
        DataTable objDT = BO_portal_tags.SelectAdmin(prefixText, 1, 10, 1);
        foreach (DataRow drow in objDT.Rows)
        {
            sb.Append(drow["TAG_NAME"]).Append(Environment.NewLine);
        }
        return sb.ToString();
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}